package sis.ra.crawlingInfobox;

import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import sis.ra.utility.Utils;


public class test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		String companyname="Yahoo!";
//		String section="Products and services|Yahoo! products";
//		section=section.substring(0,section.indexOf("|"));
//		final StringBuilder result = new StringBuilder();
//		final StringCharacterIterator iterator = new StringCharacterIterator(section);
//	    char character =  iterator.current();
//	    while (character != CharacterIterator.DONE ){
//	    	System.out.println(character);
////	    	if (character == '|') {
////	    		System.out.println(section);
////	       }
//	       character = iterator.next();
//	     }
		
//		String productspart=crawlingProducts.getInterPagePart(companyname,section);
//		System.out.println(productspart);
		String companyname="Yahoo!";
		
		System.out.print(companyname+"\t");		
		String wikipage="http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=API|"+companyname.replace(" ", "%20")+"&rvprop=content&format=xml";
		String wikicontent=Utils.fetchContentfrURL(wikipage);
		String infoboxcompany=crawlingProducts.crawlInfoBoxPartCompany(wikicontent);
		
//		System.out.println("company: "+infoboxcompany);
		ArrayList<String> products=new ArrayList<String> ();
		if (infoboxcompany.length()>2)
		{
			products=crawlingProducts.extractProcductsFrmInfoBox(infoboxcompany,companyname.replace(" ", "%20"));
		}
		System.out.print(products.size()+"\t");
		for (int j=0;j<products.size();j++)
		{
			System.out.print(products.get(j)+" ; ");
		}
		System.out.println();
	}

}
